﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DesignPattern.创建型模式.SingletonPattern._02
{
    /// <summary>
    /// 线程安全 
    /// </summary>
    public class Singleton
    {
        private volatile static Singleton _instance = null;
        private static readonly object lockHelper = new object();
        private Singleton() { }
        public static Singleton CreateInstance()
        {
            if (_instance == null)
            {
                lock (lockHelper)
                {
                    if (_instance == null)
                        _instance = new Singleton();
                }
            }
            return _instance;
        }
    }
}
